home *** CD-ROM | disk | FTP | other *** search
/ Mastering Web Site Development / Microsoft Mastering Web Site Development (Microsoft) (1997).iso / Media / SampApps / AdvWorks / AWVB5Demo.EXE / AWDataUtil.cls < prev    next >
Encoding:
Text File  |  1997-01-08  |  11.9 KB  |  278 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "AWDataUtil"
  6. Attribute VB_Creatable = True
  7. Attribute VB_Exposed = True
  8. Private adoConn As ADODB.Connection
  9. Private Const varRows As Variant = 1
  10. Private strSql As String                 ' SQL Command
  11.     
  12. Public Function AWCreate_Products()
  13.  
  14.     On Error Resume Next
  15.     strSql = "DROP TABLE Products"
  16.     adoConn.Execute strSql, varRows, -1
  17.     On Error GoTo ErrorHandler
  18.     
  19.     strSql = "CREATE TABLE Products (ProductCode varchar(10) NOT NULL PRIMARY KEY NONCLUSTERED, ProductType varchar(20) NOT NULL, ProductIntroductionDate datetime, ProductName varchar(50) NOT NULL, ProductDescription varchar(255) NOT NULL, ProductSize varchar(5), ProductImageURL varchar(255), UnitPrice float, OnSale bit, Discount int, ProductImage varchar(255))"
  20.     adoConn.Execute strSql, varRows, -1
  21.     
  22.     strSql = "CREATE  INDEX Products_byProductType ON Products(ProductType)"
  23.     adoConn.Execute strSql, varRows, -1
  24.     
  25.     'Populate Products Table
  26.     Open "Products.txt" For Input As #1
  27.     Do While Not EOF(1) ' Loop until end of file.
  28.         Input #1, ProductID, ProductCode, ProductType, ProductIntroductionDate, ProductName, ProductDescription, ProductSize, ProductImageURL, UnitPrice, OnSale, Discount, ProductImage
  29.         strSql = "INSERT INTO Products " & _
  30.                     "VALUES ('" & ProductCode & "', '" & ProductType & "', '" & _
  31.                     ProductIntroductionDate & "', '" & ProductName & "', '" & _
  32.                     ProductDescription & "', '" & ProductSize & "', '" & _
  33.                     ProductImageURL & "', " & UnitPrice & ", " & _
  34.                     OnSale & ", " & Discount & ", '" & ProductImage & "')"
  35.         adoConn.Execute strSql, varRows, -1
  36.     Loop
  37.     Close #1    ' Close file.
  38.     
  39.     On Error Resume Next
  40.     strSql = "DROP TABLE Inventory"
  41.     adoConn.Execute strSql, varRows, -1
  42.     On Error GoTo ErrorHandler
  43.         
  44.     strSql = "CREATE TABLE Inventory (ProductCode char (10) NOT NULL PRIMARY KEY NONCLUSTERED, " & _
  45.                 "QuantityOnHand int NULL , ReorderQuantity int NULL)"
  46.     adoConn.Execute strSql, varRows, -1
  47.         
  48.     'Populate Inventory Table
  49.     Open "Inventory.txt" For Input As #1
  50.     Do While Not EOF(1) ' Loop until end of file.
  51.         Input #1, InventoryID, ProductCode, QuantityOnHand, ReorderQuantity
  52.         strSql = "INSERT INTO Inventory " & _
  53.                     "VALUES ('" & ProductCode & "', " & QuantityOnHand & ", " & ReorderQuantity & ")"
  54.         adoConn.Execute strSql, varRows, -1
  55.     Loop
  56.     Close #1    ' Close file.
  57.  
  58.     On Error Resume Next
  59.     strSql = "DROP TABLE InventoryManager"
  60.     adoConn.Execute strSql, varRows, -1
  61.     On Error GoTo ErrorHandler
  62.     
  63.     strSql = "CREATE TABLE InventoryManager (Name varchar(64) NOT NULL, EMailAddress varchar(128) NULL)"
  64.     adoConn.Execute strSql, varRows, -1
  65.     
  66.     On Error Resume Next
  67.     strSql = "DROP TABLE ProductGroup"
  68.     adoConn.Execute strSql, varRows, -1
  69.     On Error GoTo ErrorHandler
  70.     
  71.     strSql = "CREATE TABLE ProductGroup (ProductGroupCode varchar(20) NOT NULL PRIMARY KEY NONCLUSTERED, ProductGroupDesc varchar(50))"
  72.     adoConn.Execute strSql, varRows, -1
  73.  
  74.     On Error Resume Next
  75.     strSql = "DROP TABLE ProductType"
  76.     adoConn.Execute strSql, varRows, -1
  77.     On Error GoTo ErrorHandler
  78.  
  79.     strSql = "CREATE TABLE ProductType (ProductTypeCode varchar(20) NOT NULL PRIMARY KEY NONCLUSTERED, ProductGroupCode varchar(20) NOT NULL, ProductTypeDesc varchar(50))"
  80.     adoConn.Execute strSql, varRows, -1
  81.     
  82.     strSql = "CREATE INDEX ProductType_byProductGroup ON ProductType(ProductGroupCode)"
  83.     adoConn.Execute strSql, varRows, -1
  84.     
  85.         'Populate the ProductGroup Table
  86.     strSql = "INSERT INTO ProductGroup VALUES ('Camping', 'Camping Equipment')"
  87.     adoConn.Execute strSql, varRows, -1
  88.     strSql = "INSERT INTO ProductGroup VALUES ('Climbing', 'Climbing Equipment')"
  89.     adoConn.Execute strSql, varRows, -1
  90.     strSql = "INSERT INTO ProductGroup VALUES ('Clothing', 'Clothing')"
  91.     adoConn.Execute strSql, varRows, -1
  92.     
  93.     'Populate the ProductType Table
  94.     strSql = "INSERT INTO ProductType VALUES ('Backpack' , 'Camping', 'Backpack')"
  95.     adoConn.Execute strSql, varRows, -1
  96.     strSql = "INSERT INTO ProductType VALUES ('Boot' , 'Clothing', 'Boot')"
  97.     adoConn.Execute strSql, varRows, -1
  98.     strSql = "INSERT INTO ProductType VALUES ('Carabiner' , 'Climbing', 'Carabiner')"
  99.     adoConn.Execute strSql, varRows, -1
  100.     strSql = "INSERT INTO ProductType VALUES ('Crampon' , 'Climbing', 'Crampon')"
  101.     adoConn.Execute strSql, varRows, -1
  102.     strSql = "INSERT INTO ProductType VALUES ('Harness' , 'Climbing', 'Harness')"
  103.     adoConn.Execute strSql, varRows, -1
  104.     strSql = "INSERT INTO ProductType VALUES ('Pants' , 'Clothing', 'Pants')"
  105.     adoConn.Execute strSql, varRows, -1
  106.     strSql = "INSERT INTO ProductType VALUES ('Parka' , 'Clothing', 'Parka')"
  107.     adoConn.Execute strSql, varRows, -1
  108.     strSql = "INSERT INTO ProductType VALUES ('RockShoes' ,'Climbing','Rock Shoes')"
  109.     adoConn.Execute strSql, varRows, -1
  110.     strSql = "INSERT INTO ProductType VALUES ('Shirt' , 'Clothing', 'Shirt')"
  111.     adoConn.Execute strSql, varRows, -1
  112.     strSql = "INSERT INTO ProductType VALUES ('SleepingBag','Camping','Sleeping Bag')"
  113.     adoConn.Execute strSql, varRows, -1
  114.     strSql = "INSERT INTO ProductType VALUES ('Supplies' , 'Camping', 'Supplies')"
  115.     adoConn.Execute strSql, varRows, -1
  116.     strSql = "INSERT INTO ProductType VALUES ('Tent' , 'Camping', 'Tent')"
  117.     adoConn.Execute strSql, varRows, -1
  118.  
  119.     Exit Function
  120.  
  121. ErrorHandler:
  122.  
  123.     Err.Raise Number:=Err.Number, Source:="AWCreate_Products", Description:=Err.Description
  124.     Exit Function
  125.  
  126. End Function
  127.  
  128.     
  129. Public Function AWCreate_Customers()
  130.  
  131.     On Error Resume Next
  132.     strSql = "DROP TABLE Customers"
  133.     adoConn.Execute strSql, varRows, -1
  134.     On Error GoTo ErrorHandler
  135.     
  136.     strSql = "CREATE TABLE Customers (CustomerID int IDENTITY (1, 1) NOT NULL PRIMARY KEY NONCLUSTERED, CustomerFirstName varchar (30) NULL , " & _
  137.                 "CustomerLastName varchar (30) NULL , BillingAddress varchar (255) NULL , City varchar (50) NULL , " & _
  138.                 "StateOrProvince varchar (20) NULL , PostalCode varchar (20) NULL , Country varchar (50) NULL , " & _
  139.                 "PhoneNumber varchar (30) NULL , EmailAddress varchar (50) NULL)"
  140.     adoConn.Execute strSql, varRows, -1
  141.     
  142.     strSql = "CREATE INDEX CustomerFullName ON Customers(CustomerLastName, CustomerFirstName)"
  143.     adoConn.Execute strSql, varRows, -1
  144.     
  145.     'Populate Customers Table
  146.     Open "Customers.txt" For Input As #1
  147.     Do While Not EOF(1) ' Loop until end of file.
  148.         Input #1, CustomerID, CustomerFirstName, CustomerLastName, BillingAddress, City, StateOrProvince, PostalCode, Country, PhoneNumber, EmailAddress
  149.         strSql = "INSERT INTO Customers (CustomerFirstName, CustomerLastName, BillingAddress, City, StateOrProvince, PostalCode, Country, PhoneNumber, EmailAddress) " & _
  150.                     "VALUES ('" & CustomerFirstName & "', '" & CustomerLastName & "', '" & _
  151.                     BillingAddress & "', '" & City & "', '" & _
  152.                     StateOrProvince & "', '" & PostalCode & "', '" & _
  153.                     Country & "', '" & PhoneNumber & "', '" & EmailAddress & "')"
  154.         adoConn.Execute strSql, varRows, -1
  155.     Loop
  156.     Close #1    ' Close file.
  157.     
  158.     Exit Function
  159.  
  160. ErrorHandler:
  161.  
  162.     Err.Raise Number:=Err.Number, Source:="AWCreate_Products", Description:=Err.Description
  163.     Exit Function
  164.  
  165.     
  166. End Function
  167.  
  168. Public Function AWCreate_Orders()
  169.  
  170.     On Error Resume Next
  171.     strSql = "DROP TABLE Orders"
  172.     adoConn.Execute strSql, varRows, -1
  173.     On Error GoTo ErrorHandler
  174.     
  175.     strSql = "CREATE TABLE Orders (OrderID int NOT NULL PRIMARY KEY NONCLUSTERED, CustomerID int NULL, OrderDate datetime NULL, " & _
  176.                 "ItemTotal float NULL, FreightCharge float NULL, SalesTax float NULL , " & _
  177.                 "OrderTotal float NULL)"
  178.     adoConn.Execute strSql, varRows, -1
  179.     
  180.     strSql = "CREATE INDEX Orders_byCustomer ON Orders(CustomerID)"
  181.     adoConn.Execute strSql, varRows, -1
  182.     
  183.     On Error Resume Next
  184.     strSql = "DROP TABLE OrderDetails"
  185.     adoConn.Execute strSql, varRows, -1
  186.     On Error GoTo ErrorHandler
  187.     
  188.     strSql = "CREATE TABLE OrderDetails (OrderDetailID int NOT NULL, OrderID int NOT NULL, ProductCode varchar (10) NOT NULL, " & _
  189.                 "Quantity int NULL, Color varchar (30) NULL, Size varchar (30) NULL, DiscountedPrice float NULL, " & _
  190.                 "ExtPrice float NULL, " & _
  191.                 "CONSTRAINT OrderDetailPrimaryKey PRIMARY KEY CLUSTERED " & _
  192.                 "(OrderID, OrderDetailID))"
  193.     adoConn.Execute strSql, varRows, -1
  194.     
  195.     strSql = "CREATE INDEX OrderDetails_byProduct ON OrderDetails(ProductCode)"
  196.     adoConn.Execute strSql, varRows, -1
  197.  
  198.     On Error Resume Next
  199.     strSql = "DROP TABLE Payments"
  200.     adoConn.Execute strSql, varRows, -1
  201.     On Error GoTo ErrorHandler
  202.     
  203.     strSql = "CREATE TABLE Payments (PaymentID int NOT NULL PRIMARY KEY CLUSTERED, OrderID int NOT NULL, PaymentAmount money NOT NULL, " & _
  204.                 "PaymentDate datetime NULL, CreditCardNumber varchar (30) NULL, CardholdersName varchar (50) NULL, " & _
  205.                 "CreditCardExpDate datetime NULL, CreditCardAuthorizationNumber varchar (30) NULL, PaymentMethodID int NOT NULL)"
  206.     adoConn.Execute strSql, varRows, -1
  207.     
  208.     strSql = "CREATE  INDEX Payments_byPaymentMethod ON Payments(PaymentMethodID)"
  209.     adoConn.Execute strSql, varRows, -1
  210.  
  211.     On Error Resume Next
  212.     strSql = "DROP TABLE PaymentAuthorization"
  213.     adoConn.Execute strSql, varRows, -1
  214.     On Error GoTo ErrorHandler
  215.  
  216.     strSql = "CREATE TABLE PaymentAuthorization (PaymentType int NOT NULL PRIMARY KEY NONCLUSTERED, PaymentAuthorize bit NOT NULL)"
  217.     adoConn.Execute strSql, varRows, -1
  218.     
  219.     On Error Resume Next
  220.     strSql = "DROP TABLE SalesTaxTable"
  221.     adoConn.Execute strSql, varRows, -1
  222.     On Error GoTo ErrorHandler
  223.     
  224.     strSql = "CREATE TABLE SalesTaxTable (State char(2) NOT NULL PRIMARY KEY NONCLUSTERED, TaxRate float NOT NULL)"
  225.     adoConn.Execute strSql, varRows, -1
  226.     
  227.     On Error Resume Next
  228.     strSql = "DROP TABLE TakeANumber"
  229.     adoConn.Execute strSql, varRows, -1
  230.     On Error GoTo ErrorHandler
  231.  
  232.     
  233.     strSql = "CREATE TABLE TakeANumber (PropertyGroupName varchar(255) NOT NULL PRIMARY KEY NONCLUSTERED, NextNumber int NOT NULL)"
  234.     adoConn.Execute strSql, varRows, -1
  235.     
  236.     'Populate Sales Tax Table
  237.     Open "SalesTax.txt" For Input As #1
  238.     Do While Not EOF(1) ' Loop until end of file.
  239.         Input #1, State, TaxRate
  240.         strSql = "INSERT INTO SalesTaxTable " & _
  241.                     "VALUES ('" & State & "', " & TaxRate & ")"
  242.         adoConn.Execute strSql, varRows, -1
  243.     Loop
  244.     Close #1    ' Close file.
  245.     
  246.     strSql = "INSERT INTO TakeANumber VALUES ('OrderID' , 1000)"
  247.     adoConn.Execute strSql, varRows, -1
  248.     strSql = "INSERT INTO TakeANumber VALUES ('PaymentID' , 2000)"
  249.     adoConn.Execute strSql, varRows, -1
  250.     
  251.     'Populate the Payment Authorization Table
  252.     strSql = "INSERT INTO PaymentAuthorization VALUES (1, -1)"
  253.     adoConn.Execute strSql, varRows, -1
  254.     strSql = "INSERT INTO PaymentAuthorization VALUES (2, -1)"
  255.     adoConn.Execute strSql, varRows, -1
  256.     strSql = "INSERT INTO PaymentAuthorization VALUES (3, -1)"
  257.     adoConn.Execute strSql, varRows, -1
  258.     strSql = "INSERT INTO PaymentAuthorization VALUES (4, -0)"
  259.     adoConn.Execute strSql, varRows, -1
  260.    
  261.     
  262.     Exit Function
  263.  
  264. ErrorHandler:
  265.  
  266.     Err.Raise Number:=Err.Number, Source:="AWCreate_Products", Description:=Err.Description
  267.     Exit Function
  268.  
  269. End Function
  270.  
  271. Private Sub Class_Initialize()
  272.     
  273.     Set adoConn = CreateObject("ADODB.Connection")
  274.     adoConn.Open strConnect, "", ""
  275.  
  276. End Sub
  277.  
  278.